/*
 * Created on 13.04.2003
 */
package de.laures.cewolf.taglib;

import java.util.ArrayList;
import java.util.List;

import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.DefaultDrawingSupplier;
import org.jfree.chart.plot.DrawingSupplier;
import org.jfree.data.general.Dataset;

import de.laures.cewolf.ChartValidationException;
import de.laures.cewolf.DatasetProduceException;
import de.laures.cewolf.style.StyleFactory;

/**
 * @author guido
 */
public class OverlaidChartDefinition extends AbstractChartDefinition {

	static final long serialVersionUID = 2620349751116074174L;

	private int xAxisType = 0;
	private int yAxisType = 0;

	private List<PlotDefinition> plotDefinitions = new ArrayList<PlotDefinition>();
	private transient DrawingSupplier drawingSupplier;

	public Dataset getDataset() throws DatasetProduceException {
		return plotDefinitions.get(0).getDataset();
	}

	public void addPlot(PlotDefinition pd) {
		pd.setDrawingSupplier(getDrawingSupplier());
		plotDefinitions.add(pd);
	}

	protected JFreeChart produceChart() throws DatasetProduceException, ChartValidationException {
		JFreeChart chart = CewolfChartFactory.getOverlaidChartInstance(type, title, xAxisLabel,
				yAxisLabel, xAxisType, yAxisType, plotDefinitions, showLegend);
		StyleFactory.applyOverlaidStyle(type, chart);
		return chart;
	}

	/**
	 * Sets the xAxisType.
	 * @param xAxisType The xAxisType to set
	 */
	public void setXAxisType(int xAxisType) {
		this.xAxisType = xAxisType;
	}

	/**
	 * Sets the yAxisType.
	 * @param yAxisType The yAxisType to set
	 */
	public void setYAxisType(int yAxisType) {
		this.yAxisType = yAxisType;
	}

	private DrawingSupplier getDrawingSupplier() {
		if (drawingSupplier == null) {
			drawingSupplier = new DefaultDrawingSupplier();
		}
		return drawingSupplier;
	}
}
